package com.ljq.software_springboot.softwareprogram.controller;


import com.ljq.software_springboot.softwareprogram.entity.Account;
import com.ljq.software_springboot.softwareprogram.entity.Change_account;
import com.ljq.software_springboot.softwareprogram.imp.AccountServiceImpl;
import org.apache.catalina.connector.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-12-18
 */
@RestController
@RequestMapping("/account")
@CrossOrigin(origins = "http://localhost:5173")
public class AccountController {
    @Autowired
    private AccountServiceImpl accountServiceImpl;
    @PostMapping("/register")
    public String register(@RequestBody Account account) {
        return accountServiceImpl.register(account.getUsername(), account.getPassword(), account.getEmail());
    }
    @PostMapping("/login")
    public String login(@RequestBody Account account) {
        return accountServiceImpl.login(account.getUsername(), account.getPassword());
    }
    @PostMapping("/info")
    public Account info(@RequestBody Map<String, String> body) {
        String name = body.get("name");  // 从请求体中获取用户名
        return accountServiceImpl.getUserByUsername(name);
    }
    @PostMapping("/change-password")
    public String changePassword(@RequestBody Change_account account) {
        return accountServiceImpl.changePassword(account.getUsername(),account.getCurrentPassword(),account.getNewPassword());
    }
    @PostMapping("/findid")
    public Integer findid(@RequestBody Account body) {
        return accountServiceImpl.findId(body.getUsername());
    }
}
